﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SYS_FILE
// * CreateDate    : 2013-12-02 21:21:16
// * Creater       : CodeSmith
// * LastChangeDate: 2013-12-02 21:21:16
// * LastChanger   : 2013-12-02 21:21:16
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sys
{
    /// <summary>
    /// SysFile
    /// </summary>
    public partial class SysFileBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSysFileEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SysFileEntity GetSysFile(SysFileEntity objSysFileEntity)
        {
            return DataAccess.SelectSingle<SysFileEntity>(objSysFileEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSysFileEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertSysFile(SysFileEntity objSysFileEntity)
        {
            return DataAccess.Insert(objSysFileEntity);
        }

        public static bool InsertSysFile(List<SysFileEntity> objSysFileEntityList)
        {
            return DataAccess.Insert(objSysFileEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSysFileEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSysFile(SysFileEntity objSysFileEntity)
        {
            return DataAccess.Update(objSysFileEntity);
        }

        public static bool UpdateSysFile(List<SysFileEntity> objSysFileEntityList)
        {
            return DataAccess.Update<SysFileEntity>(objSysFileEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSysFileEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSysFile(SysFileEntity objSysFileEntity)
        {
            return DataAccess.Delete(objSysFileEntity);
        }

        public static bool DeleteSysFile(List<SysFileEntity> objSysFileEntityList)
        {
            return DataAccess.Delete<SysFileEntity>(objSysFileEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetSysFileAll()
        {
            return DataAccess.SelectAllDataSet<SysFileEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<SysFileEntity> GetSysFileAllList()
        {
            return DataAccess.SelectAll<SysFileEntity>();
        }
        #endregion

        public static DataSet GetAllDsBySql(string sql)
        {
            return DataAccess.SelectDataSet(sql);
        }

        public static List<SysFileEntity> GetSysFileAllList(string rowId)
        {
            return DataAccess.Select<SysFileEntity>(new SysFileEntity { RowId = rowId });
        }

        


        public static DataSet GetSysFileDs(string rowId)
        {
            return DataAccess.SelectDataSet("select * from SYS_FILE where ROW_ID='"+rowId+"'");
        }

        public static bool DelSysFileAndPower(SysFileEntity file,List<SysFilePowerEntity> filePowers)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Delete(filePowers, broker);
                    DataAccess.Delete(file, broker);
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static bool DelSysFilesAndPowers(List<SysFileEntity> files,List<SysFilePowerEntity> filePowers)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Delete(filePowers, broker);
                    DataAccess.Delete(files, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }


        public static List<SysFileEntity> GetSysFileByLogicNo(string logicNo)
        {
            return DataAccess.Select<SysFileEntity>(new SysFileEntity { LogicNo = logicNo });
        }

        
    }


}

